package com.guard.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

import com.guard.R;
import com.guard.android.Constants;

public class ConnectionErrorDialogFragment extends DialogFragment {
    public static ConnectionErrorDialogFragment newInstance(String message) {
        ConnectionErrorDialogFragment dialogFragment = new ConnectionErrorDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Constants.MESSAGE, message);
        dialogFragment.setArguments(bundle);
        dialogFragment.setCancelable(false);
        return dialogFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setRetainInstance(true);
        int style = DialogFragment.STYLE_NORMAL, theme = 0;
        this.setStyle(style, theme);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new AlertDialog.Builder(getActivity()).setMessage(getResources().getString(R.string.check_internet))
                .setTitle(getArguments().getString(Constants.MESSAGE)).setIcon(R.drawable.user_picture).setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            AbstractActivity activity = (AbstractActivity) getActivity();
                            if (which == AlertDialog.BUTTON_POSITIVE) {
                                activity.onResume();
                            }
                        } catch (Exception e) {
                        }
                    }// end onClick()
                }).create();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        return dialog;
    }

}
